package
{
	import flexmdi.containers.MDICanvas;
	import flexmdi.containers.MDIWindow;
	import flexmdi.managers.MDIManager;
	
	import mx.collections.ArrayCollection;
	import mx.collections.ArrayList;
	
	public class WindowManager
	{
		private var windows:ArrayCollection;
		private  var mdiCanvas: MDICanvas;
		public function WindowManager(mdi: MDICanvas) {
			
			windows = new ArrayCollection();
			mdiCanvas = mdi;
			addWindows();
		}
		
		
		public function addWindows(): void{
			for (var i:int  ; i < mdiCanvas.windowManager.getOpenWindowList().length  ; i++) {
				if (!windows.contains(mdiCanvas.windowManager.getOpenWindowList()[i])) {
					windows.addItem(mdiCanvas.windowManager.getOpenWindowList()[i]);					
				}				
			}
		}
		
		public function contains(window:MDIWindow) : Boolean{
			for (var i:int  ; i < mdiCanvas.windowManager.getOpenWindowList().length  ; i++) {
				var win:MDIWindow = mdiCanvas.windowManager.getOpenWindowList()[i];
				return (win.className == window.className);
			}
			return false;
		}
		
		public function add(window:MDIWindow) : void{
			if (!contains(window)) {
				mdiCanvas.windowManager.add(window);				
			}
		}
	}
}